/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/itframe">itframe</a> All rights reserved.
 */
package com.rise.itframe.modules.inv.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.rise.itframe.common.config.Global;
import com.rise.itframe.common.persistence.Page;
import com.rise.itframe.common.web.BaseController;
import com.rise.itframe.modules.inv.entity.InvConf;
import com.rise.itframe.modules.inv.service.InvConfService;

/**
 * 发票白名单配置Controller
 * @author 发票白名单配置
 * @version 2017-12-31
 */
@Controller
@RequestMapping(value = "${adminPath}/inv/invConf")
public class InvConfController extends BaseController {

    @Autowired
    private InvConfService invConfService;

    @ModelAttribute
    public InvConf get(@RequestParam(required=false) String id) {
        InvConf entity = null;
        if (org.apache.commons.lang3.StringUtils.isNotBlank(id)){
            entity = invConfService.get(id);
        }
        if (entity == null){
            entity = new InvConf();
        }
        return entity;
    }

//	@RequiresPermissions("inv:invConf:view")
    @RequestMapping(value = {"list", ""})
    public String list(InvConf invConf, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<InvConf> page = invConfService.findPage(new Page<InvConf>(request, response), invConf);
        model.addAttribute("page", page);
        return "modules/inv/invConfList";
    }

    //	@RequiresPermissions("inv:invConf:view")
    @RequestMapping(value = "form")
    public String form(InvConf invConf, Model model) {
        model.addAttribute("invConf", invConf);
        return "modules/inv/invConfForm";
    }

    //	@RequiresPermissions("inv:invConf:edit")
    @RequestMapping(value = "save")
    public String save(InvConf invConf, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, invConf)){
            return form(invConf, model);
        }
        invConfService.save(invConf);
        addMessage(redirectAttributes, "保存发票白名单配置成功");
        return "redirect:"+Global.getAdminPath()+"/inv/invConf/?repage";
    }

//	@RequiresPermissions("inv:invConf:edit")
    @RequestMapping(value = "delete")
    public String delete(InvConf invConf, RedirectAttributes redirectAttributes) {
        invConfService.delete(invConf);
        addMessage(redirectAttributes, "删除发票白名单配置成功");
        return "redirect:"+Global.getAdminPath()+"/inv/invConf/?repage";
    }

}